package generic;

import java.util.*;
public class Genericexercise {
    public static void main(String[] args) {
        //使用泛型给hashset放入三个学生对象
        HashSet<Student> hs= new HashSet<Student>();
        hs.add(new Student("tom", 28));
        hs.add(new Student("jack", 18));
        hs.add(new Student("marray", 19));
        for(Student st:hs){
            System.out.println(st);
        }





        HashMap<String,Student> hm=new HashMap<String,Student>();
        hm.put("tom", new Student("tom", 28));
        hm.put("smith",new Student("smith", 112));
        hm.put("hsp",new Student("hsp", 23));
        Set<Map.Entry<String,Student>> et=hm.entrySet();
        Iterator<Map.Entry<String,Student>> it = et.iterator();
        while(it.hasNext()){
            Map.Entry<String,Student> next=it.next();
            System.out.println(next.getKey());
        }


    }
}
class Student{
    private String name;
    private int age;
    public Student(String name,int age){
        this.age=age;
        this.name=name;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public String getName() {
        return name;
    }
    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return name+" "+age;
    }
}
